package cn.zeal4j.servlet.freemarker;

import cn.zeal4j.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;

/**
 * @author Administrator
 * @file IntelliJ IDEA FreeMarker
 * @create 2020 09 21 11:21
 */
@WebServlet("fm-03")
public class FtlServlet03 extends HttpServlet {
    private static final long serialVersionUID = -8394125239520066892L;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String[] strings = {"江西", "湖北", "北京", "上海", "广州"};
        req.setAttribute("locates", strings);

        List<String> stringList = Arrays.asList("南昌", "丰城", "赣州", "九江", "吉安", "赣州");
        req.setAttribute("cityList", stringList);


        ArrayList<User> users = new ArrayList<>();
        for (int i = 1; i < 11; i++) {
            users.add(new User(i, "user-" + i, 10 + i, false));
        }
        req.setAttribute("userList", users);

        Map<String, Object> map = new HashMap<>();
        map.put("aaa", "AAA");
        map.put("bbb", "BBB");
        map.put("ccc", "CCC");
        map.put("ddd", "DDD");
        map.put("eee", "EEE");
        req.setAttribute("map", map);

        req.getRequestDispatcher("freemarker-templates/fmt-03.ftl").forward(req, resp);
    }
}
